package com.mc2.docapp.disabilityassessmenttool.UpperLimb;

import io.realm.RealmObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class C_ulca_wrist extends RealmObject {
    private CustDataType flexion_extension_arc = new CustDataType();
    private CustDataType radial_ulnar_deviation_arc = new CustDataType();
    private InnerCalculations inner_calculations = new InnerCalculations();

    public void calc(C_ulca_wrist c_ulca_wrist) {
        double a = c_ulca_wrist.getFlexion_extension_arc().getActual_right();
        double b = c_ulca_wrist.getRadial_ulnar_deviation_arc().getActual_right();
        double pa = perc(a, c_ulca_wrist.getFlexion_extension_arc().getNormal());
        double pb = perc(b, c_ulca_wrist.getRadial_ulnar_deviation_arc().getNormal());
        double x = (pa + pb) / 2.0;
        c_ulca_wrist.getFlexion_extension_arc().setPerc_loss_right(pa);
        c_ulca_wrist.getRadial_ulnar_deviation_arc().setPerc_loss_right(pb);

        a = c_ulca_wrist.getFlexion_extension_arc().getActual_left();
        b = c_ulca_wrist.getRadial_ulnar_deviation_arc().getActual_left();
        pa = perc(a, c_ulca_wrist.getFlexion_extension_arc().getNormal());
        pb = perc(b, c_ulca_wrist.getRadial_ulnar_deviation_arc().getNormal());
        double y = (pa + pb) / 2.0;
        c_ulca_wrist.getFlexion_extension_arc().setPerc_loss_left(pa);
        c_ulca_wrist.getRadial_ulnar_deviation_arc().setPerc_loss_left(pb);

        c_ulca_wrist.setInner_calculations(new InnerCalculations(
                x,
                y,
                x * 0.1,
                y * 0.1
        ));
    }

    private double perc(double a, double normal) {
        return ((normal - a) * 100d) / (normal + 0d);
    }

}
